package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentsController {
    @Autowired
    CommentsService commentsService;

    //分页查询评理列表
    @GetMapping
    public ResponseEntity findComments(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer pagesize,
                                       String movementId) {
        PageResult pr = commentsService.findComments(movementId,page,pagesize);
        return ResponseEntity.ok(pr);
    }

    /**
     * 发布评论
     */
    @PostMapping
    public ResponseEntity saveComments(@RequestBody Map map) {
        String movementId = (String )map.get("movementId");
        String comment = (String)map.get("comment");
        commentsService.saveComments(movementId,comment);
        return ResponseEntity.ok(null);
    }


    /**
     * 评论-点赞
     * 动态点赞难道不应该起名叫likeMovement吗？
     * 为什么要叫likeComment？
     * 那评论点赞叫啥啊。。。
     *
     * @param commentId
     * @return
     */
    @GetMapping("/{id}/like")
    public ResponseEntity thumbsUpComment(@PathVariable("id") String commentId) {
        Integer likeCommentCounts = commentsService.thumbsUpComment(commentId);
        return ResponseEntity.ok(likeCommentCounts);
    }


    /**
     * 评论-取消点赞
     *
     * @param commentId
     * @return
     */
    @GetMapping("/{id}/disLike")
    public ResponseEntity disLikeComment(@PathVariable("id") String commentId) {
        Integer disLikeCommentCounts = commentsService.unLikeComment(commentId);
        return ResponseEntity.ok(disLikeCommentCounts);
    }
}
